Prograph Sort XPrims contains two primitives binlist-sort and binlist-find. binlist-sort sorts a list, binlist-find uses a binary search to find an element in a sorted list.
binlist-sort
Inputs: InList; [ AttributeName ]
Outputs: OutList
Input Types: list; [ string ]
Output Types: list
Sorts a list of numbers, strings or instances in ascending order. Duplicates values are excluded from the sorted list.
If the second input, AttributeName, is omitted, the input list must contain all strings or all numbers.
If AttributeName is specified, the list must contain instances with the specified attribute. The instances are sorted by the value of AttributeName. The values of AttributeName must be either all numbers or all strings.
binlist-find
Inputs: TheList; TheItem; [ AttributeName ]
Outputs: Found; TheIndex
Input Types: list; string | number; [ string ]
Outputs: boolean; integer
Uses a binary search to find an item in a sorted list. If TheItem is not found, TheIndex is the location in the list where TheItem can be inserted.
If the second input, AttributeName, is omitted, the input list must contain all strings or all numbers.
If AttributeName is specified, the list must contain instances with the specified attribute. The instances are searched by the value of AttributeName. The values of AttributeName must be either all numbers or all strings.